﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DesktopGarden.Classes;
using System.IO;
using System.Drawing.Imaging;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace DesktopGarden.Controls
{
    /// <summary>
    /// Interaction logic for MiniFlowerDisplay.xaml
    /// </summary>
    public partial class MiniFlowerDisplay : UserControl
    {
        FlowerInstance Flower { get; set; }

        public MiniFlowerDisplay(FlowerInstance f)
        {
            InitializeComponent();
            Flower = f;
            this.DataContext = Flower;

            if (f.Image != null)
            {
                Bitmap b = new Bitmap(80, 80);
                Graphics g = Graphics.FromImage((System.Drawing.Image)b);
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                g.DrawImage(f.Image, 0, 0, 80, 80);
                g.Dispose();

                System.Drawing.Image newImage = (System.Drawing.Image)b;
                var bitmapImage = new System.Windows.Media.Imaging.BitmapImage();
                bitmapImage.BeginInit();
                MemoryStream memoryStream = new MemoryStream();
                // Save to a memory stream...
                newImage.Save(memoryStream, ImageFormat.Bmp);
                // Rewind the stream...
                memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
                bitmapImage.StreamSource = memoryStream;
                bitmapImage.EndInit();

                image.Source = bitmapImage;


                

            }
            else
                image.Visibility = System.Windows.Visibility.Collapsed;
        }


    }
}
